﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.ViewModels
{
    using System.Windows.Input;

    public delegate bool CanExecuteCommandHandler(object param);
    public delegate void ExecuteCommandHandler(object param);

    /// <summary>
    /// 表示代理命令
    /// </summary>
    public sealed class DelegateCommand : ICommand
    {
        CanExecuteCommandHandler _canExecute;
        ExecuteCommandHandler _execute;

        private DelegateCommand(CanExecuteCommandHandler canExecute, ExecuteCommandHandler execute)
        {
            _canExecute = canExecute ?? throw new NullReferenceException();
            _execute = execute ?? throw new NullReferenceException();
        }

        public event EventHandler CanExecuteChanged{
            add{
#if NETFX_DESKTOP || WINDOWS_WPF

#elif NETFX_CORE || WINDOWS_UWP
#endif
            }
            remove{
#if NETFX_DESKTOP || WINDOWS_WPF

#elif NETFX_CORE || WINDOWS_UWP
#endif
            }
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute(parameter);
        }

        public void Execute(object parameter)
        {
            _execute(parameter);
        }

        static bool AlmostTrue(object param)
        {
            return true;
        }
        

        public static DelegateCommand CreateCommand(ExecuteCommandHandler execute)
        {
            return new DelegateCommand(AlmostTrue, execute);
        }

        public static DelegateCommand CreateCommand(CanExecuteCommandHandler canExecute, ExecuteCommandHandler execute)
        {
            return new DelegateCommand(canExecute, execute);
        }
    }
}
